package com.jn.algorithm.day022.question66;

import java.util.Arrays;

/**
 * @author 江南大学1033190417
 * @date 2022/5/13 23:27
 */
public class Solution {
    public int[] plusOne(int[] digits) {
        int n = digits.length;
        int carry = 1;
        int count = n - 1;
        while (carry == 1 && count >= 0) {
            int num = digits[count] + 1;
            digits[count] = num % 10;
            carry = num / 10;
            count--;
        }
        if (carry == 1) {
            int[] newDigits = new int[n + 1];
            newDigits[0] = 1;
            for (int i = 1; i <= n; i++) {
                newDigits[i] = digits[i - 1];
            }
            return newDigits;
        }
        return digits;
    }


    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] digits = new int[]{9};
        System.out.println(Arrays.toString(solution.plusOne(digits)));
    }
}
